package com.example.demo.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BaseControllerAdvice {

    /**
     * 全局异常捕捉处理
     *
     * @param ex 系统抛出的异常
     * @return 返回错误内容
     * @throws Exception 抛出的异常
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public String errorHandler(Exception ex) throws Exception {
        System.out.println("这里是我处理的异常");
        return ex.getMessage();
    }
}
